package top.linyuxb.lycloud.admin.repository;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import top.linyuxb.lycloud.admin.entity.LyConfNodeEntity;

/**
 * Created by Intellij IDEA.
 *
 * @Author: linyuxb
 * @Date: 2024/7/29 14:58
 * @Desc:
 */
@Repository
public interface LyConfNodeRepository extends BaseRepository<LyConfNodeEntity, Long> {
    /**
     * 配置查询
     *
     * @param env
     * @param key
     * @return
     */
    LyConfNodeEntity findByEnvAndKey(String env, String key);

    /**
     * 通过id查询
     *
     * @param id
     * @param status
     * @return
     */
    LyConfNodeEntity findByIdAndStatus(Long id, Integer status);

    /**
     * 通过id更新属性
     *
     * @param value
     * @param title
     * @param id
     */
    @Modifying
    @Transactional
    @Query(value = "UPDATE ly_conf_node node SET node.`value` = ?1, `title` = ?2 where `id` = ?3 and `status` = 1", nativeQuery = true)
    void editFieldById(String value, String title, Long id);

    /**
     * 配置删除
     *
     * @param id
     * @return
     */
    @Modifying
    @Transactional
    @Query(value = "UPDATE ly_conf_node SET `status` = 0 WHERE `id` = ?1 and `status` = 1", nativeQuery = true)
    void removeById(Long id);
}
